package com.base.syslib.pulltorefresh;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ListView;

import com.base.syslib.Logs;


/**
 * Created by dufangzhu on 2017/6/8.
 */

public class CustListView extends ListView {
    public static final String TAG = "CustListView";

    public CustListView(Context context) {
        super(context);
    }

    public CustListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        Logs.v(TAG, "onInterceptTouchEvent");
        return super.onInterceptTouchEvent(ev);
    }


    float gTouchStartX = 0, gTouchStartY = 0;
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        Logs.v(TAG, "onTouchEvent");
//        return super.onTouchEvent(ev);

        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                gTouchStartX = ev.getX();
                gTouchStartY = ev.getY();
//                        Log.v(TAG, "gTouchStartX="+gTouchStartX+"  gTouchStartY="+gTouchStartY);
                break;
//                    case MotionEvent.ACTION_UP:
//                        requestDisallowInterceptTouchEvent(true);
//                        break;
            case MotionEvent.ACTION_MOVE:
                final float touchDistancesX = Math.abs(ev.getX()-gTouchStartX);
                final float touchDistancesY = Math.abs(ev.getY()-gTouchStartY);
//                        Log.v(TAG, "MotionEvent.ACTION_MOVE  gTouchStartX="+gTouchStartX+"  gTouchStartY="+gTouchStartY);
//                        Log.v(TAG, "event.getX()="+event.getX()+"  event.getY()="+event.getY());
//                        Log.v(TAG, "touchDistancesX="+touchDistancesX+"  touchDistancesY="+touchDistancesY);
                float div = (float)200 / (float)2;
//                        float div = (float)getResources().getDimension(R.dimen.game_video_item_space) * (float)5;
//                        Log.v(TAG, "div="+div);
//                if(touchDistancesY > div && touchDistancesY  >= touchDistancesX){
//                            Log.v(TAG, "--------false");
//                    requestDisallowInterceptTouchEvent(false);
//                }else{
//                            Log.v(TAG, "--------true");
//                    requestDisallowInterceptTouchEvent(true);
//                }

                requestDisallowInterceptTouchEvent(true);
                break;

            default:
                requestDisallowInterceptTouchEvent(false);
                break;
        }
        return false;
    }
    
}
